import { GSprite } from "../../../../com/mui/controls/GSprite";
import { RechargeGiftBagItem } from "../loginNotice/OpenRecharge/RechargeGiftBagItem";
import { OpenRechargeGiftBagConfig } from "../../resource/OpenRechargeGiftBagConfig";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { ItemListPanel } from "../loginNotice/OpenRecharge/ItemListPanel";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { RechargeData } from "../loginNotice/OpenRecharge/RechargeData";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class RechargeGiftItemPanel
    
    export  class RechargeGiftItemPanel extends GSprite
    {
        constructor()
        {
            super();
            this._itemArr = [];
            this.init();
            return;
        }

        public get selectedItem(): RechargeGiftBagItem
        {
            return this._selectedItem;
        }

        /* internal  */init(): void
        {
            var loc2=null;
            var loc5=null;
            var loc6=null;
            var loc1=OpenRechargeGiftBagConfig.instance.getOpenRechargeGiftBagMap();
            var loc3=9;
            var loc4=8;
            var loc7=0;
            var loc8=loc1;
            for(loc5 of loc8) 
            {
                loc2 = new RechargeGiftBagItem();
                loc2.x = loc3;
                loc2.y = loc4;
                loc2.updateData(loc5);
                addChild(loc2);
                loc3 = loc3 + loc2.pwidth + 3;
                loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onBagItemMouseClickHandler);
                this._itemArr.push(loc2);
            }
            ObjCreate.createBg(33, 162, 620, 1, this, ImagesConst.KillUserLine);
            ObjCreate.createFlowerBg(0, 162, 690, 100, this, false);
            this._itemList = new ItemListPanel();
            this._itemList.x = 100;
            this._itemList.y = 210;
            addChild(this._itemList);
            ObjCreate.createGImageBitmap(ImagesConst.RechargeWorth, 10, 200, this);
            loc6 = new GTextFormat(FontUtil.stXingkaiName, 30, 16776960);
            this._valueTxt = ObjCreate.createGTextField("588", 65, 205, 60, 40, this, loc6);
            this.updateGiftItemInfo(this._itemArr[1]);
            return;
        }

        /* internal  */onBagItemMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._itemArr.length) 
            {
                loc1 = this._itemArr[loc2];
                loc1.setClickState(false);
                ++loc2;
            }
            if (typeof arg1.target === "rechargegiftbagitem") 
            {
                loc1 = arg1.target as RechargeGiftBagItem;
            }
            else 
            {
                loc1 = arg1.currentTarget as RechargeGiftBagItem;
            }
            if (loc1) 
            {
                this.updateGiftItemInfo(loc1);
                dispatchEvent(new DataEvent(EventName.RechargeGiftBagItemSelect, loc1.code));
            }
            return;
        }

        /* internal  */updateGiftItemInfo(arg1: RechargeGiftBagItem): void
        {
            this._valueTxt.text = arg1.value + "";
            this.updateRewardList(arg1.itemCode);
            arg1.setClickState(true);
            this._selectedItem = arg1;
            return;
        }

        public updateGiftBagInfo(): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc1=RechargeData.hadGetCodes;
            if (loc1 && loc1.length > 0) 
            {
                loc3 = 0;
                while (loc3 < this._itemArr.length) 
                {
                    loc2 = this._itemArr[loc3];
                    loc4 = 0;
                    while (loc4 < loc1.length) 
                    {
                        if (loc2.code == loc1[loc4]) 
                        {
                            loc2.setGetBtn(false);
                        }
                        ++loc4;
                    }
                    loc2.updateHadGetState();
                    ++loc3;
                }
            }
            loc3 = 0;
            while (loc3 < this._itemArr.length) 
            {
                loc2 = this._itemArr[loc3];
                loc2.setCanGetState();
                loc2.updateHadGetState();
                ++loc3;
            }
            return;
        }

        /* internal  */updateRewardList(arg1: int): void
        {
            this._itemList.updateRewardList(arg1);
            return;
        }

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_itemList: ItemListPanel;

        /* internal */ /* var */_valueTxt: GTextFiled;

        /* internal */ /* var */_selectedItem: RechargeGiftBagItem;
    }
